package com.triones.api.controller.api.interlace;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.interlace.bo.*;
import com.triones.api.entity.interlace.bo.request.PhysicalCardFeesRequest;
import com.triones.api.entity.interlace.vo.*;
import com.triones.api.entity.interlace.vo.response.InfinityCardDetailsResponse;
import com.triones.api.entity.interlace.vo.response.PhysicalCardFeesResponse;
import com.triones.api.entity.param.BankCardTxnParams;
import com.triones.api.service.interlace.InterlaceFiatService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * api - interlace 法定货币相关接口
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/interlace/fiat")
public class ApiInterlaceFiatController extends BaseController {

    private final InterlaceFiatService interlaceFiatService;

    /**
     * 获取所有预算组
     */
    @GetMapping(value = "/budget/list")
    public R<List<CustomInterlaceBudgetVO>> budgetListGroup() {
        return R.ok(interlaceFiatService.budgetListGroup());
    }

    /**
     * 创建预算
     */
    @RepeatSubmit()
    @PostMapping("/budget")
    public R<Void> createBudget(@Validated @RequestBody InterlaceBudgetBO bo) {
        return toAjax(interlaceFiatService.createBudget(bo));
    }

    /**
     * 修改预算组名称
     */
    @PutMapping("/budget/{id}")
    public R<Void> updateBudgetName(@PathVariable @NotNull(message = "主键不能为空") Long id,@NotBlank(message = "名称不能为空") String name) {
        return toAjax(interlaceFiatService.updateBudgetName(id,name));
    }

    /**
     * 获取签约的卡bin信息
     * @param type BudgetCard、PrepaidCard
     */
    @GetMapping("/card/bin")
    public R<List<InterlaceCardBinsVO>> getCardBinList(String type) {
        return R.ok(interlaceFiatService.getCardBinList(type));
    }

    /**
     * 获取实体卡邮寄费用
     */
    @GetMapping("/shippingFees")
    public R<PhysicalCardFeesResponse> getPhysicalCardFees(@Validated PhysicalCardFeesRequest request) {
        return R.ok(interlaceFiatService.getPhysicalCardFees(request));
    }

    /**
     * 申请邮寄实体卡
     */
    @RepeatSubmit()
    @PostMapping("/physicalCard/ship")
    public R<Void> physicalCardShip(@Validated @RequestBody PhysicalCardShipBO bo) {
        return toAjax(interlaceFiatService.physicalCardShip(bo));
    }

    /**
     * 开预算卡
     */
    @RepeatSubmit()
    @PostMapping("/openCard/budget")
    public R<Void> openBudgetCard(@Validated @RequestBody InterlaceInfinityBudgetCardBO bo) {
        return toAjax(interlaceFiatService.openBudgetCard(bo));
    }

    /**
     * 开预付卡
     */
    @RepeatSubmit()
    @PostMapping("/openCard/prepaid")
    public R<Void> openPrepaidCard(@Validated @RequestBody InterlaceInfinityPrepaidCardBO bo) {
        return toAjax(interlaceFiatService.openPrepaidCard(bo));
    }

    /**
     * 获取卡cvv以及卡号等重要信息
     */
    @GetMapping("/card/important")
    public R<InfinityCardDetailsResponse> cardImportantInfo(@NotBlank(message = "密码不能为空") String password, @NotNull(message = "卡主键不能为空") Long id) {
        return R.ok(interlaceFiatService.cardImportantInfo(password, id));
    }

    /**
     * 量子钱包->预付卡
     */
    @PostMapping("/prepaidCard/transfer/in")
    public R<Void> prepaidCardTransferIn(@Validated @RequestBody InfinityCardTransferBO bo) {
        return toAjax(interlaceFiatService.InfinityCardTransferIn(bo));
    }

    /**
     * 预付卡->量子钱包
     */
    @PostMapping("/prepaidCard/transfer/out")
    public R<Void> prepaidCardTransferOut(@Validated @RequestBody InfinityCardTransferBO bo) {
        return toAjax(interlaceFiatService.prepaidCardTransferOut(bo));
    }

    /**
     * 增加预算
     */
    @PostMapping("/budget/increase")
    public R<Void> increaseBudget(@Validated @RequestBody BudgetChangeBO bo) {
        return toAjax(interlaceFiatService.increaseBudget(bo));
    }
    /**
     * 减少预算
     */
    @PostMapping("/budget/decrease")
    public R<Void> decreaseBudget(@Validated @RequestBody BudgetChangeBO bo) {
        return toAjax(interlaceFiatService.decreaseBudget(bo));
    }

    /**
     * 预算交易列表
     */
    @GetMapping("/budget/transactionPageList/{id}")
    public TableDataInfo<CustomInterlaceBudgetTransactionVO> budgetTransactionPageList(@PathVariable @NotNull(message = "预算组id不能为空") Long id, PageQuery pageQuery) {
        return interlaceFiatService.budgetTransactionPageList(id,pageQuery);
    }

    /**
     * 预算组下面的预算卡列表
     */
    @GetMapping("/budget/cardList/{id}")
    public R<List<InterlaceInfinityCardVO>> budgetCardList(@PathVariable @NotNull(message = "预算组id不能为空") Long id) {
        return R.ok(interlaceFiatService.budgetCardList(id));
    }

    /**
     * 预付卡列表
     */
    @GetMapping("/prepaid/cardList")
    public R<List<InterlaceInfinityCardVO>> prepaidCardList() {
        return R.ok(interlaceFiatService.prepaidCardList());
    }

    /**
     * 卡交易列表（首页使用）
     */
    @GetMapping("/card/transactionPageList")
    public TableDataInfo<CustomInterlaceCardTransactionVO> cardTransactionPageList(PageQuery pageQuery) {
        return interlaceFiatService.cardTransactionPageList(pageQuery);
    }

    /**
     * 卡交易详情
     */
    @GetMapping("/card/transactionDetail/{id}")
    public R<CustomInterlaceCardTransactionVO> cardTransactionDetail(@PathVariable @NotNull(message = "交易id不能为空") Long id) {
        return R.ok(interlaceFiatService.cardTransactionDetail(id));
    }

    /**
     * 查询实体卡邮寄信息地址
     */
    @GetMapping("/physicalCard/shipInfo/{cardId}")
    public R<InterlaceShipPhysicalCardsVO> getPhysicalCardShipInfo(@PathVariable @NotNull(message = "卡id不能为空") Long cardId) {
        return R.ok(interlaceFiatService.getPhysicalCardShipInfo(cardId));
    }

    /**
     * 冻结卡
     */
    @PostMapping("/card/freeze/{id}")
    public R<Void> freezeCard(@PathVariable @NotNull(message = "卡id不能为空") Long id) {
        return toAjax(interlaceFiatService.freezeCard(id));
    }

    /**
     * 解冻卡
     */
    @PostMapping("/card/unfreeze/{id}")
    public R<Void> unfreezeCard(@PathVariable @NotNull(message = "卡id不能为空") Long id) {
        return toAjax(interlaceFiatService.unfreezeCard(id));
    }

    /**
     * 卡列表
     */
    @GetMapping("/cardList")
    public R<List<InterlaceInfinityCardVO>> cardList() {
        return R.ok(interlaceFiatService.cardList());
    }

    /**
     * 卡详情
     */
    @GetMapping("/card/detail/{id}")
    public R<CustomInterlaceInfinityCardVO> cardDetail(@PathVariable @NotNull(message = "卡id不能为空") Long id) {
        return R.ok(interlaceFiatService.cardDetail(id));
    }

    /**
     * 获取实体卡制作费用
     */
    @GetMapping("/cardProductionFee")
    public R<PhysicalCardFeesResponse> cardProductionFee(@NotBlank(message = "卡BIN不能为空") String bin) {
        return R.ok(interlaceFiatService.cardProductionFee(bin));
    }

    /**
     * 开卡申请记录
     */
    @GetMapping("/cardApply/list")
    public R<List<InterlaceCardApplyVO>> cardApplyList() {
        return R.ok(interlaceFiatService.cardApplyList());
    }

    /**
     * 卡交易列表
     */
    @GetMapping("/card/transaction/pageList")
    public TableDataInfo<CustomInterlaceCardTransactionVO> transactionPageList(@Validated BankCardTxnParams params,PageQuery pageQuery) {
        return interlaceFiatService.transactionPageList(params,pageQuery);
    }

    /**
     * 实体卡签收
     */
    @PostMapping("/card/delivered/{id}")
    public R<Void> delivered(@PathVariable @NotNull(message = "卡id不能为空") Long id) {
        return toAjax(interlaceFiatService.delivered(id));
    }

    /**
     * 删除银行卡卡片
     */
    @DeleteMapping("/card/del")
    public R<Void> delCard(@NotBlank(message = "密码不能为空") String password, @NotNull(message = "卡主键不能为空") Long id) {
        return toAjax(interlaceFiatService.delCard(password, id));
    }

    /**
     * 根据cardId获取账单月份统计数据
     */
    @GetMapping("/card/billMonthStatistics/{cardId}")
    public R<List<InterlaceCardBillStatisticsVO>> getBillMonthStatistics(@PathVariable("cardId") @NotBlank(message = "卡id不能为空") String cardId,@NotBlank(message = "查询年不能为空") String year) {
        return R.ok(interlaceFiatService.getBillMonthStatistics(cardId,year));
    }

    /**
     * 速度控制
     */
    @PostMapping("/card/velocityControl")
    public R<Void> velocityControl(@Validated @RequestBody VelocityControlBO bo) {
        return toAjax(interlaceFiatService.velocityControl(bo));
    }
}
